﻿<!doctype html>
<html lang="en">

<head>
    <title>Registration</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="application/x-javascript">
        addEventListener("load", function () {
            setTimeout(hideURLbar, 0);
        }, false);

        function hideURLbar() {
            window.scrollTo(0, 1);
        }
    </script>

    <!-- css -->
    <link href="../../static/css/register.css" rel="stylesheet" type='text/css' media="all" />
    <!-- /css -->
</head>

<body>
    <h1 class="w3layouts">Editting Infomation </h1>
    <div class="clear"></div>
    <div class="content-w3ls">
        <div class="form_w3layouts">
            <form action="#" method="post" class="agile_form">
                <!--form reset-->
                <div class="agileits-left">
                    <input type="text" class="username" placeholder="Name/姓名" required="">
                </div>
                <div class="checkin agileits-left">
                    <input placeholder="Date of Birth/出生日期" class="date" name="date" id="datepicker" type="text" value="" onfocus="this.value = '';"
                           onblur="if (this.value == '') {this.value = '';}" required="" />
                </div>
                <div class="agileits-left s2-w3ls">
                    <input type="text" name="number" class="phone" placeholder="Phone Number/手机号码" required="">
                </div>
                <div class="agileits-left">
                    <input type="email" name="email" class="email" placeholder="E-mail/邮箱" required="">
                </div>
                <div class="section_class_agileits check">
                    <select id="sex">
                        <option value="">Choice of sex/性别</option>
                        <option value="male/男">male/男</option>
                        <option value="female/女">female/女</option>
                    </select>
                </div>
                <div class="section_class_agileits check">
                    <select id="politics">
                        <option value="">Politics status/政治面貌</option>
                        <option value="party number/党员">party number/党员</option>
                        <option value="common citizen/普通公民">common citizen/普通公民</option>
                    </select>
                </div>
                <div class="section_class_agileits check">
                    <select id="educat">
                        <option value="" >Education background/学历</option>
                        <option value="college degree/专科学历">college degree/专科学历</option>
                        <option value="bachelor degree/本科学历">bachelor degree/本科学历</option>
                        <option value="master degree/硕士学历">master degree/硕士学历</option>
                        <option value="postdoctoral degree/博士学历">postdoctoral degree/博士学历</option>
                    </select>
                </div>
                <div class="agileits-left">
                    <input type="text" name="nation" class="nation" placeholder="Nation/民族" required="">
                </div>
                <div class="section_class_agileits check">
                    <select id="depart" required>
                        <option value="">Department/所属部门</option>
                        <!--  
                        <option value="business department/商务部">business department/商务部</option>
                        <option value="technology department/技术部">technology department/技术部</option>
                        <option value="marketing department/市场部">marketing department/市场部</option>
                        <option value="management department/管理层">management department/管理层</option>
                        -->
                    </select>
                </div>
                <!--
                <div class="agileits-left">
                    <input type="password" name="password" class="password" placeholder="Password/密码" required="">
                </div>
                <div class="agileits-left">
                    <input type="password" name="repassword" class="repassword" placeholder="Repassword/确认密码" required="">
                </div>
                <div class="agileits-left">
                    <input type="text" id="timepicker" name="time" class="timepicker form-control" placeholder="Select Time" value="">
                </div>-->
                <!--//form reset-->
                <div class="submit-w3l">
                    <input type="button" value=" Save Editting" id="register">
                </div>
            </form>
        </div>
        <div class="clear"></div>
    </div>
    <div class="clear"></div>
    <h2 class="copyright-agileits">
        © 2018 hhit Registration. All Rights Reserved | Design by Gen
        <a href="#" target="_blank">CSAT_Gen</a>
    </h2>
    <div class="clear"></div>

    <!-- js -->
    <script src="../js/jquery-2.2.3.min.js"></script>
    <!-- //js -->
    <!-- date-->
    <link rel="stylesheet" href="../css/jquery-ui.css" />
    <script src="../../static/js/jquery-ui.js"></script>
    <script>
		$(function () {
			$("#datepicker,#datepicker1").datepicker();
		});
    </script>
    <!-- //date -->
    <!-- time -->
    <script type="text/javascript" src="../js/wickedpicker.js"></script>
    <script type="text/javascript">
		$('.timepicker').wickedpicker({
			twentyFour: false
		});
    </script>
    <link href="../css/wickedpicker.css" rel="stylesheet" type='text/css' media="all" />
    <!-- //time -->
    <script type="text/javascript">
    
    $(function () {
    	
    	//获取地址链接问号后面参数的值
        //url  地址 getUrl(location.href).Id;
        getUrl = function (url) {
            url = !url ? location.search : url;
            var temp = {};
            if (url.indexOf("?") != -1) {
                var params = url.substr(url.indexOf("?") + 1).split("&");
                for (var i = 0; i < params.length; i++) {
                    var param = params[i].split("=");
                    temp[param[0]] = param[1];
                }
                return temp;
            } else {
                return false;
            }
        }
        var id = getUrl(location.href).id;
        var sminsalary ='';
        function loadinfo(){
        	$.ajax({
                type: "Post",
                url: "/hr_doc/servlet/StaffServlet",
                data: {
               	 Command:"load",
               	 id:id
                },
                async: false,
                dataType: "json",
                success: function (d) {
                	console.log(d);
    	           	if(d.code == 1){
    	           		var item  = d.result;
    	           		$(".username").val(item.sname);
    	           		$(".date").val(item.sbirthday);
    	           		$(".phone").val(item.sphone);
    	           		$(".email").val(item.semail);
    	           		$("#sex").find("option[value='"+item.ssex+"']").attr("selected",true);
    	           		$("#politics").find("option[value='"+item.spolitic+"']").attr("selected",true);
    	           		$("#educat").find("option[value='"+item.seducat+"']").attr("selected",true);
    	           		$(".nation").val(item.snation);
    	           		$("#depart").find("option[value='"+item.sdepartname+"']").attr("selected",true);
    	           		sminsalary = item.sminsalary;
    	           		
    	           	}else{
    	           		alert("用户信息不存在");
    	           		location.href = "/hr_doc/subPage/resetStaff.html";
    	           	}
                },
                error: function (xmlHttpRequest, textStatus, errorThrown) {
                	//location.href = "/project/stuLogin.html";
                }
            });
        }
        
        
        
    	
    	
    	
    	var departlist = null;
    	$.ajax({
            type: "Post",
            url: "/hr_doc/servlet/DepartServlet",
            data: {
           	 Command:"list",
            },
            async: false,
            dataType: "json",
            success: function (d) {
            	console.log(d);
           	 if(d.code == 1){
           		 departlist = d.result;
           		 //location.href = location.reload();
           		 //$("#depart")
           		  var str = '';
           		 for(var i = 0;i<departlist.length;i++){
           			 var item = departlist[i];
           			 str +='<option value="'+item.dname+'">'+item.dname+'</option>';   			
           		 }
           		 $("#depart").append(str);
           		loadinfo();
           	 }
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
            	//location.href = "/project/stuLogin.html";
            }
        });
    	
    	$("#register").click(function (){
        	
    		var sname = $(".username").val();
    		if(sname == null || sname == ""){
    			alert("姓名不能为空");
    			return;
    		}
    		
    		var date = $(".date").val();
    		if(date == null || date == ""){
    			alert("出生日期不能为空");
    			return;
    		}
    		
    		var phone = $(".phone").val();
    		if(phone == null || phone == ""){
    			alert("手机号码不能为空");
    			return;
    		}
    		
        	var email = $(".email").val();
        	if(email == null || email == ""){
    			alert("邮箱不能为空");
    			return;
    		}
        	
    		var sex = $("#sex").val();
    		if(sex == null || sex == ""){
    			alert("性别不能为空");
    			return;
    		}
    		
        	var politics = $("#politics").val();
        	if(politics == null || politics == ""){
    			alert("政治面貌不能为空");
    			return;
    		}
        	
        	var educat = $("#educat").val();
        	if(educat == null || educat == ""){
    			alert("学历不能为空");
    			return;
    		}
        	
        	var nation = $(".nation").val();
        	if(nation == null || nation == ""){
    			alert("民族不能为空");
    			return;
    		}
        	
    		var depart = $("#depart").val();
    		var departno = 0;
    		for(var i = 0;i<departlist.length;i++){
    			var ditem = departlist[i];
    			if(ditem.dname == depart){
    				departno = ditem.dno;
    			}
    		}
    		if(departno == 0){
    			alert("请选择对应的部门");
    			return;
    		}
    		
    		$.ajax({
                type: "Post",
                url: "/hr_doc/servlet/StaffServlet",
                data: {
               	 Command:"modify",
               	 id:id,
               	 sbirthday:date,
               	 sname:sname,
               	 ssex:sex,
               	 spolitic:politics,
               	 seducat:educat,
               	 snation:nation,
               	 sdepartname:depart,
               	 sdepartno:departno,
               	 sphone:phone,
               	 sminsalary:sminsalary,
               	 semail:email,
                },
                async: false,
                dataType: "json",
                success: function (d) {
                	console.log(d);
               	 if(d.code == 1){
               		 alert(d.result);
               		 location.href = "/hr_doc/subPage/staffRecord.html";
               	 }else{
               		alert(d.result);
               	 }
                },
                error: function (xmlHttpRequest, textStatus, errorThrown) {
                	//location.href = "/project/stuLogin.html";
                }
            });
    		
        });
    	
    	
    	}
    );
    </script>
    
</body>
</html>